﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace _0712502_0712504_DesignPatternGame
{
    static public class GlobalVariables
    {
        public static int SCREEN_WIDTH = 1024;
        public static int SCREEN_HEIGHT = 768;
        
        public static int[,] gatePostions;
        public static int numOfEnemyTank = 0;       // So luong enemy tank cho man choi
        public static int maxEnemyTankAvailable;    // So luong tank xuat hie.n toi da trong man choi
        public static int[] numOfEnemyTanks = new int[8];
        public static int numOfTank1, numOfTank2, numOfTank3, numOfTank4, numOfTank5, numOfTank6, numOfTank7, numOfTank8, numOfTank9, numOfTank10;
        public static int typeOfEnemyTank = 8;
        public static int[] enemyTankHPs = new int[8];
        public static int numOfGate;
        public static Point playerTankStartPos;   // Vi tri xuat hien cua player tank
        public static int playerLife;   // Số mạng của player tank
        public static int playerMaxHP;  // Số máu lớn nhất của player tank
        public static int playerCurHP;  // Số máu hiện tại của player tank
        public static int playerEXP;    // Điểm kinh nghiệm của người chơi
        
        // Bat-tat hieu ung am thanh
        static bool _haveSoundEffect = true;
        public static bool HaveSoundEffect
        {
            get { return GlobalVariables._haveSoundEffect; }
            set { GlobalVariables._haveSoundEffect = value; }
        }

        // Bat-tat nha.c trong game
        static bool _haveSongEffect = true;
        public static bool HaveSongEffect
        {
            get { return GlobalVariables._haveSongEffect; }
            set { GlobalVariables._haveSongEffect = value; }
        }

        // Man choi
        static short _iCurrentStage;
        public static short iCurrentStage
        {
            get { return GlobalVariables._iCurrentStage; }
            set { GlobalVariables._iCurrentStage = value; }
        }

        // Ban do choi game


        // So luong xe tang di.ch cho man choi
        static int _amountOfEnemyTanks;
        public static int AmountOfEnemyTanks
        {
            get { return GlobalVariables._amountOfEnemyTanks; }
            set { GlobalVariables._amountOfEnemyTanks = value; }
        }

        // So luong xe tang di.ch hien co trong man choi
        static int _amountOfCurrentEnemyTanks;
        public static int AmountOfCurrentEnemyTanks
        {
            get { return GlobalVariables._amountOfCurrentEnemyTanks; }
            set { GlobalVariables._amountOfCurrentEnemyTanks = value; }
        }

        // Gia tri do lon hie.u ung am thanh cho game
        static short _volumeOfSoundEffect;
        public static short VolumeOfSoundEffect
        {
            get { return GlobalVariables._volumeOfSoundEffect; }
            set { GlobalVariables._volumeOfSoundEffect = value; }
        }

        // Gia tri do lon cua nha.c cho game
        static short _volumeOfSongEffect;
        public static short VolumeOfSongEffect
        {
            get { return GlobalVariables._volumeOfSongEffect; }
            set { GlobalVariables._volumeOfSongEffect = value; }
        }

        // So luong nguoi choi
        static short _nPlayers;
        public static short nPlayers
        {
            get { return GlobalVariables._nPlayers; }
            set { GlobalVariables._nPlayers = value; }
        }

        static short _gameLevel;
        public static short GameLevel
        {
            get { return GlobalVariables._gameLevel; }
            set { GlobalVariables._gameLevel = value; }
        }


        // Cai chi ko hieu?
        static Texture2D _backgroundMap;
        public static Texture2D BackgroundMap
        {
            get { return GlobalVariables._backgroundMap; }
            set { GlobalVariables._backgroundMap = value; }
        }

        public static bool CheckRectCollision(Rectangle rect1, Rectangle rect2)
        {
            if (rect1.Contains(rect2.Location))
            {
                return true;                
            }

            if (rect1.Contains((rect2.X + rect2.Width - 1), rect2.Y))
            {
                return true;
            }
            if (rect1.Contains((rect2.X + rect2.Width - 1), (rect2.Y + rect2.Height - 1)))
            {
                return true;
            }
            if (rect1.Contains(rect2.X, (rect2.Y + rect2.Height - 1)))
            {
                return true;
            }
            if (rect2.Contains(rect1.Location))
            {
                return true;
            }
            if (rect2.Contains((rect1.X + rect1.Width - 1), rect1.Y))
            {
                return true;
            }
            if (rect2.Contains((rect1.X + rect1.Width - 1), (rect1.Y + rect1.Height - 1)))
            {
                return true;
            }
            if (rect2.Contains(rect1.X, (rect1.Y + rect1.Height - 1)))
            {
                return true;
            }
            return false;
        }

        public static bool IsPlayerTankID(IDTank IdTank)
        {
            if (IdTank == IDTank.idPlayerTankLevel1 ||
               IdTank == IDTank.idPlayerTankLevel2 ||
               IdTank == IDTank.idPlayerTankLevel3)   // Đạn của ComTank
            {
                return true;
            }
            return false;
        }
    }
}
